<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Title</title>

</head>

<body>
我的页面

<script src="js/jquery-1.7.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
    //页面加载时执行
    $(function () {
        var code = getQueryString("code");
        if(code!=null&&code!=""){
            getUserMsg(code);
        }
    })
    //获取用户信息
    function getUserMsg(code) {
        $.ajax({
            url: '/oauth2-demo/getUserMsg',
            method: 'POST',
            data: {
                code: code,
                client_id: "dbb8b982ad154f699805914b0a4c79a5",
                redirect_uri: "http://localhost:8089/oauth2-demo/my.html"
            },
            success: function (result) {
                var resultObj = eval('(' + result + ')');
                var type = resultObj.code;
                console.log(resultObj);
                if (type == "200") {
                    var msg = resultObj.data;
                    alert(JSON.stringify(msg));
                    console.log(msg);
//                    loginMsg(msg);
                }
            }

        });
    }
    
    function loginMsg(msg) {
        $.ajax({
            url: '/oauth2-demo/loginMsg',
            method: 'POST',
            data: {
                msg: msg,
            },
            success: function (result) {
                console.log(result)
            }

        });
    }
    
    //获取域名中的参数值
    function getQueryString(urlStr) {
        var result = window.location.search.match(new RegExp("[\?\&]" + urlStr + "=([^\&]+)", "i"));
        console.log(result);
        if (result == null || result.length < 1) {
            return "";
        }
        return result[1];
    }


</script>

</body>

</html>